package com.guanghua.brick.html.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MappingTag extends BodyTagSupport {
	
private static Log logger = LogFactory.getLog(MappingTag.class);
	
	private String pageField = null;
	private String optionField = null;
	private String optionValue = null;

	public int doEndTag() throws JspException {
		//找到父亲，并add html
		Tag tag = this.getParent();
		if (tag instanceof ControlBindTag) {
			((ControlBindTag)tag).addBindMap(pageField, (optionField==null)?pageField:optionField);
		} else if (tag instanceof ControlBindOptionTag) {
			((ControlBindOptionTag)tag).addOptionField(optionField, optionValue);
		} else {
			logger.warn("mapping parent must be bind or bind option");
		}
		return BodyTagSupport.EVAL_PAGE;
	}

	public String getOptionValue() {
		return optionValue;
	}

	public void setOptionValue(String optionValue) {
		this.optionValue = optionValue;
	}

	public String getPageField() {
		return pageField;
	}

	public void setPageField(String pageField) {
		this.pageField = pageField;
	}

	public String getOptionField() {
		return optionField;
	}

	public void setOptionField(String optionField) {
		this.optionField = optionField;
	}
	
	
}
